package pkd.vs.struts.action.authentication;

import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.util.Enumeration;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

public class LoginAction extends DispatchAction{
	
	protected ActionForward dispatchMethod(ActionMapping mapping, 
			ActionForm form, 
			HttpServletRequest request, 
			HttpServletResponse response, 
			String methodName) throws Exception {
		// TODO Auto-generated method stub
		String methodToCall=null;
		try
		{
			if (methodName!=null)
			{
				getMethod(methodName);
			}else{
					}
			methodToCall=methodName;
		}catch (NoSuchMethodException exc){
			methodToCall="login";
		}
		return super.dispatchMethod(mapping, form, request, response, methodToCall);

	}
	
	public ActionForward login(ActionMapping mapping,
			ActionForm form,
			HttpServletRequest request,
			HttpServletResponse response) {
		String methodName = "[login]";
		DatabaseMetaData dm = null;
        ResultSet rs = null;
		for (Enumeration e = request.getParameterNames(); e.hasMoreElements();) {	
			String name = (String)e.nextElement();
		}
		try{
			HttpSession session = request.getSession(false);
			if (session != null){
			     session.invalidate();
			}
			
			
		}catch(Exception ex){
			ex.printStackTrace();
		}
		System.out.println(methodName+ "[START]");
		return mapping.findForward("showPage");
	}
}
